#ifndef __H_STRING_CONVERT__
#define __H_STRING_CONVERT__

#include "tstring.h"
#include "scoped_ptr.h"

namespace bl
{
	inline std::string wstring2ansi(const wchar_t* str)
	{
#if (defined WIN32)
		int len = WideCharToMultiByte(CP_ACP, 0, str, -1, 0, 0, 0, 0);
		scoped_array<char> buf(new char[len]);
		WideCharToMultiByte(CP_ACP, 0, str, -1, buf.get(), len, 0, 0);
		return std::string(buf.get());
#endif
	}

	inline std::wstring ansi2wstring(const char* str)
	{
#if (defined WIN32)
		int len = MultiByteToWideChar(CP_ACP, 0, str, -1, 0, 0);
		scoped_array<wchar_t> buf(new wchar_t[len]);
		MultiByteToWideChar(CP_ACP, 0, str, -1, buf.get(), len);
		return std::wstring(buf.get());
#endif
	}

	inline std::string wstring_to_utf8(const wchar_t* str)
	{
#if (defined WIN32)
		int len = WideCharToMultiByte(CP_UTF8, 0, str, -1, 0, 0, 0, 0);
		scoped_array<char> buf(new char[len]);
		WideCharToMultiByte(CP_UTF8, 0, str, -1, buf.get(), len, 0, 0);
		return std::string(buf.get());
#endif
	}

	inline std::wstring utf8_to_wstring(const char* str)
	{
#if (defined WIN32)
		int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, 0, 0);
		scoped_array<wchar_t> buf(new wchar_t[len]);
		MultiByteToWideChar(CP_UTF8, 0, str, -1, buf.get(), len);
		return std::wstring(buf.get());
#endif
	}

	inline std::string wstring2ansi(const std::wstring str)  { return wstring2ansi(str.c_str()); }
	inline std::wstring ansi2wstring(const std::string str) {return ansi2wstring(str.c_str()); }
	inline std::string wstring2utf8(const std::wstring str) {return wstring2utf8(str.c_str()); }
	inline std::wstring utf82wstring(const std::string str) {return utf82wstring(str.c_str()); }
}

#endif